/*
 * Interpolator.h
 *
 *  Created on: 31 déc. 2009
 *      Author: math
 */

#ifndef INTERPOLATOR_H_
#define INTERPOLATOR_H_

#include "LutBound.h"
#include <vector>
#include <boost/function.hpp>




class BoundInterpolator {
public:
    typedef boost::function<int(int,int,double)> channelInterType;
    enum InterpolatorType {
      linear,
      min,
      max
    };

    BoundInterpolator();
    BoundInterpolator(InterpolatorType inter_type);

    channelInterType getChannelInterpolator() const;
    void setChannelInterpolator(channelInterType interpolator);
    LutColor interpole(const LutBound &B1, const LutBound &B2, double pos);
private:
    channelInterType m_channelInterpolator;
};

struct ChannelInterpolatorMax {
    int operator()(int a, int b, double pos) const {
        return std::max<int>(a,b);
    }
};

struct ChannelInterpolatorMin {
    int operator()(int a, int b, double pos) const {
        return std::min<int>(a,b);
    }
};

struct ChannelInterpolatorLinear {
    int operator()(int a, int b, double pos) const {
        return static_cast<unsigned int> (a*(1-pos) +pos*b);
    }
};

#endif /* INTERPOLATOR_H_ */
